package com.vitas.coin.resp

import android.util.Log
import com.snap.common.bean.resp.RespBean
import com.snap.http.HttpUtil
import com.snap.http.request.addParam
import com.snap.http.request.asResponse
import com.snap.util.AesEncryptUtil
import com.snap.util.GsonUtil
import com.vitas.coin.data.bean.VoiceCateRecommendBean

/**
 * @description:
 * @author: Funky
 * @date: 2024/10/21 13:02
 */
object VideoResp {

    suspend fun getUrl(url: String, action: (VoiceCateRecommendBean?) -> Unit) {
        Log.e("tagg", "start req")
        HttpUtil.get("https://jk.y-l.cc/api/dsp/3240EB6120B97E82CEDAA757A6D8CC1A17C46F076ED9714079/202037242")
            .addParam("url", url)
            .asResponse<RespBean<String>>()
            .onSuccess {
                Log.e("tagg", "request tabs success, " + it.data)
                if (it.isSuccess()) {
                    val data = AesEncryptUtil.decrypt(it.data)
                    val bean = GsonUtil.fromJson(data, VoiceCateRecommendBean::class.java)
                    action.invoke(bean)
                }
            }
            .onFailure {
                Log.e("tagg", "request fail")
                action.invoke(null)
            }
    }
}